package test;

import comment.Comment;

/**
 *create by tbj
 */
public class MyBinarySearch {
	public static int search(int[] a,int target){
		int l=0;
		int r=a.length-1;
		while(l <= r){
			int mid=l+(r-l)/2;
			if(a[mid] > target){
				r=mid-1; 
			}else if(a[mid] < target){
				l=mid+1;
			}else{
				return mid;
			}
		}
		return -1;
	}
	public static void main(String[] args) {
		int[] a=Comment.getOrderedArray(11);
		System.out.println(MyBinarySearch.search(a, 2));
	}
}
